package database

import (
	"gorm.io/gorm"
	"sensi/common/frame"
	"time"
)

// Model ...
type Model struct {
	ID         int    `gorm:"column:id;primaryKey" json:"id"`
	CreateTime string `gorm:"column:create_time" json:"create_time"`
	UpdateTime string `gorm:"column:update_time" json:"update_time"`
}

// BeforeCreate ...
func (m *Model) BeforeCreate(tx *gorm.DB) error {
	m.CreateTime = time.Now().Format(frame.TimeFormatTime)
	m.UpdateTime = time.Now().Format(frame.TimeFormatTime)
	return nil
}

// BeforeUpdate ...
func (m *Model) BeforeUpdate(tx *gorm.DB) error {
	m.UpdateTime = time.Now().Format(frame.TimeFormatTime)
	return nil
}

// SoftDelete ...
type SoftDelete struct {
	DeleteTime gorm.DeletedAt `gorm:"column:delete_time" json:"-"`
}
